import { observable, action } from 'mobx';
import _ from 'lodash';
import data from './languageData'

function loopData(obj, language) {
  let key;
  if(_.isObject(obj)){
    for(key in obj){
      let that = obj[key];
      if (_.isArray(that)) {
        _.each(that, (item)=>{
          loopData(item, language);
        });
      }
      if (_.isObject(that)) {
        if(_.has(that, 'cn')&&_.has(that, 'en')){
          obj[key] = that[language];
        }
      }
    }
  }
}

function getLanguageData(data, language) {
  let back = _.cloneDeep(data);
  loopData(back, language)
  return back
}

export default class LanguageStore {
  @observable language = 'cn';    //  'cn' or 'en'

  constructor(initState) {
  }

  @action getPartnerCodeList(){
    
  }

  getPageData(pageName){
  	return getLanguageData(data[pageName], this.language)
  }
}
